<template>
  <div class="wrapper" ref="wrapper">
    <div class="content">
      <slot></slot>
    </div>
  </div>
</template>

<script>
import BScroll from 'better-scroll'

export default {
  name: "Scroll",
  data() {
    return {
      scroll: null
    }
  },
  props: {
    probeType: {
      type: Number,
      default: 0
    },
    
  },
  mounted() {
    this.scroll = new BScroll((this.$refs.wrapper), {
      // 监听鼠标位置，包括惯性滑动
      // 配置上拉加载功能
      pullUpLoad: this.pullUpLoad,
      click: true,
      probeType: this.probeType
    }) 
    this.scroll.on("scroll", (position) => {
      //console.log(position);
      // 将鼠标的滚动事件传给父组件，监听滚动事件
      this.$emit("scroll", position);
    });
    // this.scroll.finishPullUp("pullingUp", () => {
    //   this.$emit('pullingUp')
    // })
    
  },
  methods: {
    scrollTo(x, y, time=500) {
      this.scroll.scrollTo(x, y, time)
    },
    finishPullUp() {
      this.scroll.finishPullUp()
    }
  }
}
</script>

<style scoped>
  .wrapper {
    overflow: hidden;
  }
</style>